/**
 * User: muxin4ever
 * Date: Oct, 31, 2012
 * Time: 21:25
 */

package gui;

import handler.CalculationHandler;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;

import common.MyButton;
import common.MyComboBox;
import common.MyLabel;
import common.MyPanelLeft;

public class PanelCalculationBar extends MyPanelLeft {
	private FrameMain f = null;

	private MyButton buttonOp = new MyButton(new ImageIcon(
			"./image/labelOperation.png"));
	private MyLabel label = new MyLabel(new ImageIcon(
			"./image/panelCalculation.png"));
	private MyButton buttonM1 = new MyButton(new ImageIcon(
			"./image/labelMatrix1.png"));
	private MyButton buttonM2 = new MyButton(new ImageIcon(
			"./image/labelMatrix2.png"));
	private MyButton buttonCalc = new MyButton(new ImageIcon(
			"./image/buttonCalculate.png"));
	private MyButton buttonTab = new MyButton();

	private String matrixNameList[] = { "A", "B", "C" };

	private MyComboBox operation = new MyComboBox(CalculationHandler.opFullName);
	private MyComboBox matrixSelect1 = new MyComboBox(matrixNameList);
	private MyComboBox matrixSelect2 = new MyComboBox(matrixNameList);

	public PanelCalculationBar(FrameMain frameMain) {
		f = frameMain;

		label.setBounds(0, 0, 300, 600);

		buttonTab.setBounds(150, 70, 130, 35);

		buttonOp.setBounds(45, 130, 218, 43);
		operation.setBounds(45, 180, 218, 43);
		buttonM1.setBounds(45, 230, 218, 43);
		matrixSelect1.setBounds(45, 280, 218, 43);
		buttonM2.setBounds(45, 330, 218, 43);
		matrixSelect2.setBounds(45, 380, 218, 43);
		buttonCalc.setBounds(40, 430, 231, 88);

		label.add(buttonTab);
		label.add(buttonOp);
		label.add(buttonM1);
		label.add(buttonM2);
		label.add(buttonCalc);
		label.add(operation);
		label.add(matrixSelect1);
		label.add(matrixSelect2);
		this.add(label);

		MouseListener listenerTab = new MouseListener() {
			public void mouseEntered(MouseEvent e) {
			}

			public void mouseClicked(MouseEvent arg0) {
				setVisible(false);
				f.getPanelOrganizerBar().setVisible(true);
				//f.getPanelDisplayMatrix().setVisible(false);
			}

			public void mouseExited(MouseEvent arg0) {
			}

			public void mousePressed(MouseEvent arg0) {
			}

			public void mouseReleased(MouseEvent arg0) {
			}
		};
		buttonTab.addMouseListener(listenerTab);

		MouseListener listenerCalculate = new MouseListener() {
			public void mouseEntered(MouseEvent e) {
			}

			public void mouseClicked(MouseEvent arg0) {
				f.getOutputHandler().writeCommandFile((String)operation.getSelectedItem(),
						(String)matrixSelect1.getSelectedItem(),
						(String)matrixSelect2.getSelectedItem());
				f.getDialogNameResultMatrix().setVisible(true);

			}

			public void mouseExited(MouseEvent arg0) {
			}

			public void mousePressed(MouseEvent arg0) {
			}

			public void mouseReleased(MouseEvent arg0) {
			}
		};
		buttonCalc.addMouseListener(listenerCalculate);
	}

	public void setMatrixNameList(String[] list) {
		matrixNameList = list;
		matrixSelect1.removeAllItems();
		matrixSelect2.removeAllItems();
		matrixSelect1.addItem("");
		matrixSelect2.addItem("");
		for (String str : list) {
			matrixSelect1.addItem(str);
			matrixSelect2.addItem(str);
		}

	}
}
